home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / progwin.zip / SCRAMBLE.ZIP / SCRAMBLE.C next >
C/C++ Source or Header  |  1991-11-10  |  2KB  |  50 lines

  1. /*------------------------------------------------
  2.   SCRAMBLE.C -- Scramble (and Unscramble) Screen
  3.                 (c) Charles Petzold, 1990
  4.   ------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <stdlib.h>
  8. #define NUM 200
  9.  
  10. long FAR PASCAL WndProc(HWND, WORD, WORD, LONG);
  11.  
  12. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  13.                    LPSTR lpszCmdLine, int nCmdShow)
  14. {
  15.   static short nKeep[NUM][4];
  16.   HDC hdc = CreateDC("DISPLAY",NULL,NULL,NULL);
  17.   HDC hdcMem = CreateCompatibleDC(hdc);
  18.   short cxSize = GetSystemMetrics(SM_CXSCREEN) / 10;
  19.   short cySize = GetSystemMetrics(SM_CYSCREEN) / 10;
  20.   HBITMAP hBitmap = CreateCompatibleBitmap(hdc, cxSize, cySize);
  21.   short i, j, x1, y1, x2, y2;
  22.  
  23.   SelectObject(hdcMem, hBitmap);
  24.  
  25.   srand(LOWORD(GetCurrentTime()));
  26.  
  27.   for (i=0; i<2; i++)
  28.     for (j=0; j<NUM; j++)
  29.     {
  30.       if (i==0)
  31.       {
  32.         nKeep[j][0] = x1 = cxSize * (rand() % 10);
  33.         nKeep[j][1] = y1 = cySize * (rand() % 10);
  34.         nKeep[j][2] = x2 = cxSize * (rand() % 10);
  35.         nKeep[j][3] = y2 = cySize * (rand() % 10);
  36.       }
  37.       else
  38.       {
  39.         x1 = nKeep[NUM - 1 - j][0];
  40.         y1 = nKeep[NUM - 1 - j][1];
  41.         x2 = nKeep[NUM - 1 - j][2];
  42.         y2 = nKeep[NUM - 1 - j][3];
  43.       }
  44.       BitBlt(hdcMem, 0, 0, cxSize, cySize, hdc, x1, y1, SRCCOPY);
  45.       BitBlt(hdc, x1, y1, cxSize, cySize, hdc, x2, y2, SRCCOPY);
  46.       BitBlt(hdc, x2, y2, cxSize, cySize, hdcMem, 0, 0, SRCCOPY);
  47.     }
  48.   return FALSE;
  49. }
  50.